package cn.tedu.ivos.repair.service.impl;

import cn.tedu.ivos.repair.mapper.RepairMapper;
import cn.tedu.ivos.repair.pojo.dto.RepairQuery;
import cn.tedu.ivos.repair.pojo.dto.RepairSaveParam;
import cn.tedu.ivos.repair.pojo.entity.Repair;
import cn.tedu.ivos.repair.pojo.vo.RepairVO;
import cn.tedu.ivos.repair.service.RepairService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


import java.util.Date;
import java.util.List;

@Slf4j
@Service
public class RepairServiceImpl implements RepairService {
    @Autowired
    private RepairMapper repairMapper;
    @Override
    public List<RepairVO> selectRepairVehicle(RepairQuery repairQuery) {
        List<RepairVO> list =repairMapper.selectRepairVehicle(repairQuery);
        return list;
    }

    @Override
    public void saveRepair(RepairSaveParam repairSaveParam) {
        log.debug("保存维修信息 repairSaveParam={}", repairSaveParam);
        Repair repair = new Repair();
        BeanUtils.copyProperties(repairSaveParam, repair);
        if (repair.getId()==null){
            repair.setRepairTime(new Date());
            repairMapper.insert(repair);
        }else {
            repairMapper.update(repair);
        }
    }

    @Override
    public void deleteRepair(Long repairId) {
         repairMapper.delete(repairId);
    }
}
